package com.cskaoyan.controller.issue;

import com.cskaoyan.bean.MallIssue;
import com.cskaoyan.model.bo.PageBo;
import com.cskaoyan.model.vo.BaseData;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.service.issue.IssueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: mjm
 * @Date: 2021/11/30
 * @Time: 22:06
 * @Description:
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {
    @Autowired
    IssueService issueService;


    /**
     * @description: 获取通用问题列表
     * @param:
     * @return:
     */
    @RequiresPermissions("admin:issue:list")
    @GetMapping("list")
    public BaseRespVo issueList(PageBo pageBo,String question){
        BaseData baseData = issueService.issueList(pageBo, question);
        return BaseRespVo.ok(baseData);

    }


    /**
     * @description: 创建通用问题
     * @param:
     * @return:
     */
    @RequiresPermissions("admin:issue:create")
    @PostMapping("create")
    public BaseRespVo issueCreate(@RequestBody MallIssue mallIssueBo){

        MallIssue mallIssueVo = issueService.issueCreate(mallIssueBo);
        return BaseRespVo.ok(mallIssueVo);
    }

    /**
     * @description: 编辑通用问题
     * @param:
     * @return:
     */
    @RequiresPermissions("admin:issue:update")
    @PostMapping("update")
    public BaseRespVo issueUpdate(@RequestBody MallIssue mallIssueBo){
        MallIssue mallIssueVo = issueService.issueUpdate(mallIssueBo);
        return BaseRespVo.ok(mallIssueVo);
    }


    /**
     * @description: 删除通用问题
     * @param:
     * @return:
     */
    @RequiresPermissions("admin:issue:delete")
    @PostMapping("delete")
    public BaseRespVo issueDelete(@RequestBody MallIssue mallIssue){
        int affectedRows = issueService.issueDelete(mallIssue);
        if(affectedRows == 1){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }
}
